<%@ page language="java" isELIgnored="false" import="java.util.*"
	pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><s:text name="monitor.addTitle" /></title>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/fare/js/show.js"></script>
<link rel="stylesheet"
	href="http://qunarzz.com/home/prd/styles/geilivible/release/home-2013012823365302.css">
<script type="text/javascript"
	src="<%=request.getContextPath()%>/fare/js/jquery-1.6.4.min.js"></script>
<%-- <script src="<%=request.getContextPath()%>/fare/js/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>  --%>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/fare/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/fare/lib/ligerUI/js/ligerui.min.js"></script>
<script
	src="<%=request.getContextPath()%>/fare/js/ligerUI/js/core/base.js"
	type="text/javascript"></script>
<link
	href="<%=request.getContextPath()%>/fare/lib/ligerUI/skins/Aqua/css/ligerui-all.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript"
	src="<%=request.getContextPath()%>/FusionCharts/FusionCharts.js"></script>
<link href="<%=request.getContextPath()%>/fare/css/base.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript"
	src="<%=request.getContextPath()%>/jsFile/common.js"></script>
<link rev="stylesheet" media="all"
	href="<%=request.getContextPath()%>/fare/css/form_style.css"
	type="text/css" rel="stylesheet">
<script type="text/javascript"
	src="<%=request.getContextPath()%>/fare/lib/ligerUI/js/plugins/ligerCheckBox.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/fare/js/json2.js"></script>
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/fare/fdc/style.css" />
<script type="text/javascript"
	src="<%=request.getContextPath()%>/fare/lib/ligerUI/js/ligerui.min.js"></script>
<script
	src="<%=request.getContextPath()%>/fare/lib/jquery/jquery.form.js"
	type="text/javascript"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/fare/lib/ligerUI/js/ligerui.min.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/fare/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/jsFile/multiblepicker.js"></script>
<link href='<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css' rel="stylesheet" type="text/css" />
	<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/citylist.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script>
<!-- 圆角文本框 -->
<link href="<%=request.getContextPath()%>/fare/css/htc/htc.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript">
//window.CHENKED_FLIGHTS=new Array();
//var CHENKED_FLIGHTS=new Array();
//初始化航线
$(document).ready(function(){
	var alerFlighDate=document.getElementById("monitor.settingAddHasSel").value;
	window.CHENKED_FLIGHTS=new Array();
	window.CHECKED_STR=alerFlighDate; 
	$('#depCity').querycity({'data':citysFlight,'tabs':labelFromcity});
	$('#arrCity').querycity({'data':citysFlight,'tabs':labelFromcity});
	/* $('#departcitys').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	$('#arrivalcitys').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList}); */
//	reurl();

	
	
});
	

function checkForm(){
	    var alerFlighDate=document.getElementById("share.alertSelectFlighDate").value;
	    var alerFlighSel=document.getElementById("monitor.settingAddSel").value;
	    var alertLocalSel=document.getElementById("share.showDifferent2").value;
		var queryDates=document.getElementById("queryDate").value;
		var depCity=document.getElementById("depCity").value;
		var arrCity=document.getElementById("arrCity").value;
		var flag=true;
		if(queryDates=='' || queryDates == null ){
			flag=false;
			alert(alerFlighDate);
			return;
		}
		if (depCity == '中文/拼音'|| arrCity == '中文/拼音') {
			flag = false;
			alert(alertLocalSel);
			return;
		}
		if(depCity == arrCity){
			flag = false;
			alert(alertLocalSel);
		}
		if(CHENKED_FLIGHTS.length==0){
			flag=false;
			var b=confirm(alerFlighSel);
			if(b==true){
				window.close();
			}
		}
		return flag;
	}

function changeAir(){
	//加载城市组件
	$('#depCity').querycity({'data' : citysFlight, 'tabs' : labelFromcity });
	$('#arrCity').querycity({'data' : citysFlight,'tabs' : labelFromcity });
	$("#depCity").css({color:'black'});
	$("#arrCity").css({color:'black'});
	
	//禁用面板操作
	$("#flightnos").attr("disabled","disabled");
	var carrierKey=$("#airCompany").val();
	var fromCityName=$("#depCity").val();
	var toCityName=$("#arrCity").val();
	changeAirs();
	<%-- $.ajax({
		url:"<%=request.getContextPath()%>/freightMonitorSettingsAction!isGrabLines.action",
		data:{
			carrierKey:carrierKey,
			fromCity:fromCityName,
			toCity:toCityName
		},
		type:'post',
		dataType:'json',
		cache : false, 
	    async : false,
	    beforeSend:function(){},
	    success:function(data){
	    	var results=data[0].state;
	    	if(results=="isHas"){
	    		changeAirs();
	    	}else{
	    		$("#flightnos option").remove();
	    		alert("该航线没有抓取，请重新设置！");
	    	}
	    },
	    error:function(){},
	    complete:function(){}
	}); --%>
	
}


function changeAirs(){
	var carrierKey=$("#airCompany").val();
	if(carrierKey==undefined || carrierKey==""){$("#flightnos option").remove();return ;}
	//获取航空公司的航线下的航班
	var fromCityCodes=$("#depCity").val();
	var toCityCodes=$("#arrCity").val();
	$.ajax({
		url:"<%=request.getContextPath()%>/freightMonitorSettingsAction!getFlightNo.action",
		data:{
			companyCarrierKey:carrierKey,
			fromCityCodes:fromCityCodes,
			toCityCodes:toCityCodes,
		},
		type:'post',
		dataType:'json',
		cache : false, 
	    async : false,
	    beforeSend:function(){},
	    success:function(data){
	    	displayFlight(data);
	    },
	    error:function(){},
	    complete:function(){}
	});
}
//显示航班号
function displayFlight(data){
	//清除之前的航班
	$("#flightnos option").remove();
	if(data && data.length>0){
		//启用面板操作(如:双击添加)
		$("#flightnos").removeAttr("disabled");
		for(var i=0;i<data.length;i++){
			if(isExistFlight(data[i].flightNo)==true){
			/* 	alert(data[i].flightNo+data[i].companyCode); */
				$("#flightnos").append("<option value='"+data[i].flightNo+"/"+data[i].companyCode+"'>"+data[i].flightNo+CHECKED_STR+"</option>");
			}else{
				$("#flightnos").append("<option value='"+data[i].flightNo+"/"+data[i].companyCode+"'>"+data[i].flightNo+"</option>");
			}
			
		}
	}
}
//是否存在航班号
function isExistFlight(f){
	var str=CHENKED_FLIGHTS.join("|");
	return str.indexOf(f)==-1?false:true;
}

//添加或删除被选择的航班
function addOrRemoveChioce(e){
	var alertSelectFli=document.getElementById("monitor.settingAddSeled").value;
	if(CHENKED_FLIGHTS.length < 5){
	var str=CHENKED_FLIGHTS.join("|");
	var op=$(e).find("option:selected");
	if(str.indexOf($(e).val())==-1){//不存在该航班
		CHENKED_FLIGHTS.unshift($(e).val());//放入
		$(op).text($(op).text()+CHECKED_STR);
	}else{//存在
		str=str.replace($(e).val(),"");
		var strs=str.split("|");
		CHENKED_FLIGHTS=[];
		for(var i=0;i<strs.length;i++){
			if(strs[i]!=null && $.trim(strs[i])!="" && strs[i]!="|"){
				CHENKED_FLIGHTS.push(strs[i]);
			}
		};
		$(op).text($(op).text().replace(CHECKED_STR,""));
	}
	flushCheckedFlights();
	}else{
		alert(alertSelectFli);
	}
}
//刷新已经选择的航班
function flushCheckedFlights(){
	
	var table=$("#airLine");
	$(table).empty();
	var rowSize=5;//一行容纳多少个航班，动态的生成表格
	for(var i=1;i<=CHENKED_FLIGHTS.length;i++){
		if(i%rowSize==1){
			table.append("<tr></tr>");
		}
		$("tr:last",table).append("<td style='padding:5px 5px 5px 0px;border-bottom:0px;'>"
		+"<input type='checkbox' name='airLine' value='"+CHENKED_FLIGHTS[i-1]+"' checked='checked'  onclick='changeChecked(this)'/>&nbsp&nbsp"+CHENKED_FLIGHTS[i-1]
		+"</td>");
	}
}
//改变选项
function changeChecked(e){
	if($(e).attr("checked")!=true){//不选则删除他，同时需要改变select的显示方式还有全局变量
		var str=CHENKED_FLIGHTS.join("|");
		str=str.replace($(e).val(),"");
		var strs=str.split("|");
		CHENKED_FLIGHTS=[];
		for(var i=0;i<strs.length;i++){
			if(strs[i]!=null && $.trim(strs[i])!="" && strs[i]!="|"){
				CHENKED_FLIGHTS.push(strs[i]);
			}
		};
		flushCheckedFlights();
		$("#flightnos option").each(function(){
			if($(this).val()==$(e).val()){
				$(this).text($(this).val());
				return;
			}
		});
	}
}
//清除所有选项
function clearAll(){
	CHENKED_FLIGHTS=[];
	flushCheckedFlights();
	$("#flightnos option").each(function(){
			$(this).text($(this).val());
	});
}

function add(){	
	var sureAlert=document.getElementById("share.sureAdd").value;
	var failureAlert=document.getElementById("share.fail").value;
	if(checkForm() ){
	if(	confirm(sureAlert)){
		   $("#lineEditForm").ajaxSubmit({
			   url:"<%=request.getContextPath()%>/freightMonitorSettingsAction!saveMonitor.action",
		    	type:"POST",
		    	async:false,
		    	cache : false, 
		   //	dataType:'json',
		   // 	contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		    	 beforeSend:function(){	 },
		    	success:function(data){
		    		closeCheckedWindow();
		    	},
		    	 error:function(){
		    		 alert(failureAlert);
		    	 },
		 	    complete:function(){}
		    });
		}
	}
}

function sureConfig(){
	var alertSeleE=document.getElementById("monitor.settingAddSel").value;
	if(CHENKED_FLIGHTS.length==0){
		var b=confirm(alertSeleE);
		if(b==true){
			closeCheckedWindow();
		}
	}else{
		closeCheckedWindow();
	}
}
//关闭这个窗口
function closeCheckedWindow(){
	var successAlert=document.getElementById("share.success").value;
	alert(successAlert);
	var pWin = window.dialogArguments.pWin;//父窗口
	window.close();
	pWin.showDataAgain();
	
	
}
//刷新当前页面一次
 function reurl(){
	 url = location.href; 
	 var times = url.split("?"); 
	 if(times[1] != 1){ 
	 url += "?1"; 
	 self.location.replace(url);
	 }
}
</script>
</head>

<body>
	<div class="form_body">
		<div class="main_max">
			<div class="high_10"></div>
			<div class="form_table_tltle">
				<s:text name="monitor.settingAddPage" />
			</div>
			<form method="post" id="lineEditForm" action="">
				<input type="hidden" name="fromCityName" id="fromCityName">
				<input type="hidden" name="toCityName" id="toCityName"> <input
					type="hidden" name="result" id="result" value="${result}" />

				<!-- internationalization  -->
				<input type="hidden" id="share.sureDel"
					value="<s:text name="share.sureDel"/>" /> <input type="hidden"
					id="share.alertSelectFlighDate"
					value="<s:text name="share.alertSelectFlighDate"/>" /> <input
					type="hidden" id="share.fail" value="<s:text name="share.fail"/>" />
				<input type="hidden" id="share.success"
					value="<s:text name="share.success"/>" /> <input type="hidden"
					id="share.showDifferent2"
					value="<s:text name="share.showDifferent2"/>" /> <input
					type="hidden" id="monitor.settingAddSel"
					value="<s:text name="monitor.settingAddSel"/>" /> <input
					type="hidden" id="monitor.settingAddHasSel"
					value="<s:text name="monitor.settingAddHasSel"/>" /> <input
					type="hidden" id="monitor.settingAddSeled"
					value="<s:text name="monitor.settingAddSeled"/>" /> <input
					type="hidden" id="share.sureAdd"
					value="<s:text name ="share.sureAdd"/>" />
				<table width="0" border="0" cellpadding="0" cellspacing="0"
					class="form_table">
					<tr>
						<td class="left"><s:text name="share.flightDate" />：</td>
						<td><input name="queryDate" type="text" id="queryDate"
							style="width: 129px"
							onClick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d',maxDate:'${maxDate}' ,lang:'<s:text name='forms.locale'/>'})"
							readonly="readonly" /> <span style="color: #ff0000">* <s:text
									name="monitor.settingSelectDays" /></span></td>

					</tr>
					<tr>
						<td class="left"><s:text name="share.flightLine" /> ：</td>
						<td>
						<%-- <jsp:include page="/inc/flightSelect.jsp"></jsp:include> --%>
						<c:if test="${language=='en_US'}">
							<jsp:include page="/inc/flightSelect_en_Us.jsp"></jsp:include>
		   				</c:if>
				 		<c:if test="${language=='zh_CN' or language=='other'}">
				 			<jsp:include page="/inc/flightSelect.jsp"></jsp:include>
						</c:if>

						</td>
					</tr>
					<tr>
						<td class="left"><s:text name="share.airlineCompany" />:</td>
						<td><select name="airCompany" id="airCompany"
							onchange="javascript:changeAir();"
							style="width: 200px; padding: 0px;">
								<option value="">
									--
									<s:text name="share.select" />
									--
								</option>
								<c:forEach var="item" items="${crawlCompanys}">
									<option value="${item.carrierKey}">${item.name}</option>
								</c:forEach>
						</select></td>
					</tr>
					<tr>
						<td class="left"><s:text name="share.flighNumber" />:</td>
						<td><select multiple="multiple" id="flightnos"
							name="flightnos" style="height: 200px; width: 200px;"
							ondblclick="addOrRemoveChioce(this)" disabled>
						</select> <!--  
							<img style="cursor: pointer;"
								src="<%=request.getContextPath()%>/fare/images/but_03.png"
								name="querybutton" id="querybutton" onclick="addChioce()"/>
							--> <s:text name="monitor.settingClickS" /></td>
					</tr>
					<tr>
						<td class="left"><s:text name="monitor.settingSelectFlighs" />:
						</td>
						<td>
							<!--  
							<input type="text" id="chiocevalue222" name="chiocevalue222" value="" style="width:350px;" readonly="readonly"/>
							-->
							<table id="airLine"></table> <!-- ///	<table id="hbaseKey" type="display:true"></table> -->

						</td>
					</tr>
					<tr>
						<td class="right" colspan="2"
							style="padding-top: 10px; padding-left: 150px;">
							<img
							src="<%=request.getContextPath() %>/<s:text name ='monitor.addBut'/>"
							name="querybutton" id="querybutton" onclick="javascript:add();" />
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<img
							src="<%=request.getContextPath() %>/<s:text name ='monitor.emptyBut'/>"
							name="cancelbutton" id="cancelbutton"
							onclick="javascript:clearAll();" /> 
							<%-- <input type="button" onclick="javascript:add();" value=""
							class="<s:i18n name='forms'><s:text name='forms.btn07'></s:text></s:i18n>"
							id="querybutton" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
							<input type="button" onclick="javascript:clearAll();" value=""
							class="<s:i18n name='forms'><s:text name='forms.btn02'></s:text></s:i18n>"
							id="cancelbutton" /> --%>
							
						</td>
					</tr>
				</table>
			</form>
			<%-- <script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script> --%>
</body>
</html>
